<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/pages/common/header.jsp"%>
 <script type="text/javascript" src="<%=request.getContextPath() %>/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript">
var id = "<s:property value="#parameters['id']"/>";
var gridManager;
$(function (){
	gridManager=$("#maingrid").ligerGrid({
        checkbox:true,
        height : '230px',
        rowHeight: 28,//行默认的高度
        headerRowHeight: 30,//表头行的高度
        usePager: false,
        columns: [
	         { display: '起飞时间类型', name: 'dayType', width : 80, render:function(data,index,value){
	        	 return "<input style='text-align:center;width:95%;height:95%' id='"+data.id+"dayType' value='"+data.dayType+"'/>";
	         }},   
	         { display: '指定起飞间隔', name: 'assignFlightDay',width : 85, render:function(data,index,value){
	        	 return "<input style='text-align:center;width:95%;height:95%' id='"+data.id+"assignFlightDay' value='"+data.assignFlightDay+"'/>";
	         }},   
	         { display: '指定回程间隔', name: 'assignRoundDay',width : 85,render:function(data,index,value){
	        	 return "<input style='text-align:center;width:95%;height:95%' id='"+data.id+"assignRoundDay' value='"+data.assignRoundDay+"'/>";
	         }},   
	         { display: '固定开始日期', name: 'startDate',width : 100,render:function(data,index,value){
	        	 return "<input onClick=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" id='"+data.id+"startDate' style='text-align:center;width:95%;height:95%' value='"+data.startDate+"'/>";
	         }}, 
	         { display: '固定结束日期', name: 'endDate',width : 100,render:function(data,index,value){
	        	 return "<input onClick=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" id='"+data.id+"endDate' style='text-align:center;width:95%;height:95%' value='"+data.endDate+"'/>";
	         }}, 
	         { display: '未来周期', name: 'futureCycle',width : 65,render:function(data,index,value){
	        	 return "<input style='text-align:center;width:95%;height:95%' id='"+data.id+"futureCycle' value='"+data.futureCycle+"'/>";
	         }}, 
	       ], 
       enabledEdit: false, clickToEdit: false,  
       parms : [
            	{name:"templateVO.id",value: id},
                ],
       url:"<%=contextPath %>/airlinemanagement-TaskTemplateConfig-listAssignDay.action",
       width: '581px',
       toolbar: { items: [
            { id: "add", text: '增加', click: itemclick, icon: 'add' },
            { line: true }, 
            { id: "remove", text: '删除', click: itemclick, icon: 'delete' },
            { line: true }, 
            { id: "save", text: '保存', click: itemclick, icon: 'save' }
        ]
        }
   });
	autoResize();
});

function itemclick(item)
{
	switch (item.id) {
		case "add":
			addDataAction();
	        break;
		case "remove":
			deleteAction();
	        break;
		case "save":
			modifyDataAction();
	        break;
	}
}

/*删除行*/
function deleteAction()
{ 
    var newRow = gridManager.getSelected();
    if (!newRow) { alert('请选择行'); return; }
    
    var removeData = '';
	  $.each(gridManager.getCheckedRows(), function(index, element) {
		  removeData = removeData + element.id + ',';
	  });
	  removeData = removeData.substr(0, removeData.length - 1) ;
    var data = [{ name: 'ids', value: removeData }];
	 Koala.ajax({
 		async:true,
 		type : "POST",
 		url: "<%=contextPath %>/airlinemanagement-TaskTemplateConfig-deleteAssignDay.action",
 		data:data,
 		dataType:'json',
 		success: function(data, textStatus){
  			 gridManager.deleteSelectedRow();
  			 gridManager.loadData();
 		}
 		});
}

function modifyDataAction(){
	var newRow = gridManager.getSelected();
    if (!newRow) { alert('请选择行'); return; }
	var url = '<%=contextPath %>/airlinemanagement-TaskTemplateConfig-saveAssignDayFun.action';
    $.each(gridManager.getCheckedRows(), function(index, element) {
    	var savedata=[{ name: 'assignDayVO.id', value: element.id },
		       	  {name:'assignDayVO.templateId',value:element.templateId },
		       	  {name:'assignDayVO.dayType',value:$('#'+element.id+'dayType').val() },
		       	  {name:'assignDayVO.assignFlightDay',value:$('#'+element.id+'assignFlightDay').val() },
		       	  {name:'assignDayVO.assignRoundDay',value:$('#'+element.id+'assignRoundDay').val() },
		       	  {name: 'assignDayVO.startDate', value: $('#'+element.id+'startDate').val() },
		       	  {name:'assignDayVO.endDate',value:$('#'+element.id+'endDate').val() },
		       	  {name:'assignDayVO.futureCycle',value:$('#'+element.id+'futureCycle').val() }];
   	   Koala.ajax({
   			type : 'POST',
   			url: url,
   			dataType:'json',
   			data: savedata,
   			success: function(json){
   				if(json && json.result && json.result=="success"){
   				 gridManager.loadData();
   				}else{
   					alert(json.result);
   				}
   			}
   		});
	  });
}

function addDataAction(){
	var url = '<%=contextPath %>/airlinemanagement-TaskTemplateConfig-saveAssignDayFun.action';
   Koala.ajax({
		type : 'POST',
		url: url,
		dataType:'json',
		data: [{ name: 'assignDayVO.templateId', value: id },
		       	  {name:'assignDayVO.dayType',value:2},
		       	  {name:'assignDayVO.assignRoundDay',value:7},
		       	  {name:'assignDayVO.assignFlightDay',value:0},
		       	  {name:'assignDayVO.futureCycle',value:0}],
		success: function(json){
			if(json && json.result && json.result=="success"){
			 gridManager.loadData();
			}else{
				alert(json.result);
			}
		}
	});
}

function autoResize(){
	var _form = $("#form_body");
	var width = 585;
	var height = _form.height() + 100;
	if(height<240)height = 240;
	try {
		$(parent.document).find("div.l-dialog-body:last").height(height).width(width);
		$(parent.document).find('div.l-dialog-content:last').height(height-5);
	} catch (e) {}
}
</script>
</head>
<body>
<div class="form_body">
	<!-- <form id="dataForm" name="dataForm" class="form_data">
 		<table>
 			<tr>
 			<td>指定起飞类型:</td>
 			<td><select name="assignDayVO.dayType" class="select-common">
 						<option value="1">指定日期区间</option>
 						<option value="2">未来固定日期天数</option>
 						<option value="3">未来每周周几</option>
 						<option value="4">每月第几天</option>
 						<option value="5">每季第几天</option>
 						<option value="6">未指定</option>
 					</select>
 			</td>
 			<td>指定起飞间隔:</td>
 			<td><input type="text" class="input-common" name="assignDayVO.assignFlightDay"/></td>
 			<td></td>
 			<td></td>
 			</tr>
 		</table>
 		<input type="submit" onclick="saveDataAction()" value="新增"/>
  	</form> -->
 	<div  id="maingrid"></div>
</div>
</body>
</html>
